package tech.wangpai.multi.datasource.repository;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestMapping;
import tech.wangpai.multi.datasource.domain.User;

import java.util.List;
@Repository
public class UserRepository {
    @Autowired
    @Qualifier("jdbcTemplateOne")
    private JdbcTemplate jdbcTemplateOne;

    @Autowired
    @Qualifier("jdbcTemplateTwo")
    private JdbcTemplate jdbcTemplateTwo;

    @RequestMapping("/test")
    public void test() {
        List<User> users1 = jdbcTemplateOne.query("SELECT * FROM sys_user",
                new BeanPropertyRowMapper<>(User.class));
        List<User> users2 = jdbcTemplateTwo.query("SELECT * FROM sys_user",
                new BeanPropertyRowMapper<>(User.class));
        System.out.println("数据库1>>>users>>>" + users1);
        System.out.println("数据库2>>>users>>>" + users2);
        return;
    }
}
